<style type="text/css">
</style>

<div class="red" style="font-size: 14px; margin-bottom: 10px;">
    <div>注：充值成功后，系统会根据配置的打水倍率，自动修改打水余额！</div>
    <div>【操作指引】打水余额指的是：用户再投注多少钱即可提款。充值时打水余额会增加，下注结算后打水余额会减少。</div>
    <div>【操作指引】打水余额为0时，用户可以申请提款。</div>
</div>

<table class="form-table-without-line">
    <tr>
        <th>用户名</th>
        <td>
            <input type="text" class="am-form-field username" placeholder="请输入用户名">
            <div class="clue balance">当前打水余额：<span class="red">--</span></div>
        </td>
    </tr>

    <tr>
        <th>打水余额</th>
        <td>
            <input type="number" class="am-form-field amount" placeholder="请输入新的打水金额，元">
        </td>
    </tr>

    <tr>
        <th>备注</th>
        <td>
            <textarea placeholder="备注，最多60个文字" class="memo" maxlength="120" rows="5"></textarea>
            <button class="btn-charge">提交</button>
            <div class="clue">注意：提交成功后，请到“打水记录”中进行二次审核</div>
        </td>
    </tr>
</table>

<script>
    var userinfo = context.center.user;
    function fillUserInfoForBalance() {
        $(".username").val(userinfo.mobile);
        $(".btn-charge").removeAttr("disabled");
        for (var i in userinfo.account) {
            if (userinfo.account[i].owner == "") {
                $(".balance .red").html((userinfo.account[i].dw/100).toFixed(2));
                return;
            }
        }
        $(".balance .red").html(0);
    }
    if (userinfo) fillUserInfoForBalance();

    var _queryUserInfo = function() {
        $(".btn-charge").attr("disabled", true);
        $(".balance .red").html("--");

        // 查找用户信息
        userinfo = null;
        var n = $(".username").val().trim();
        if (n == '') return;
        CMD.find_user_by_name(n, function(r) {
            if (r.list.length == 0) {
                $(".username").val("");
                alert2("用户" + n + "不存在！", true);
                return;
            }

            userinfo = r.list[0];
            fillUserInfoForBalance();
        });
    }
    $(".username").change(function() {
        _queryUserInfo();
    });
    if (urlInfo.params.uid) {
        $(".username").val(urlInfo.params.uid);
        _queryUserInfo();
    }

    $(".btn-charge").click(function() {
        if (!userinfo) return;
        var amount = $(".amount").val().trim();
        if (amount == '') {
            alert2("金额不对！", true);
            return;
        }
        amount = parseInt(amount);
        if (amount < 0) {
            alert2("打水余额不能为负数！", true);
            return;
        }

        startLoading();
        CMD.modify_account_dw(userinfo.id, amount * 100, function() {
            stopLoading();
            alert2("提交成功，请到“打水记录”中审核通过后生效！");
        })
    });
</script>
